using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TimeWar.Octree;
using Microsoft.Xna.Framework;

namespace TimeWar
{
    public class CRenderedObjectOctree : ITimeWarObject
    {
        protected internal CRenderedObjectOctreeNode top;
        //protected BoundingFrustum m_cameraFrustum = null;

        public CRenderedObjectOctree()
        {
            //these parameters worked on Vista, but not necessarily for a XBox 360
            //top = new CRenderedObjectOctreeNode(1, 0, 1, 0, 1, 0, 8, 1);

            //XBox 360 parameters
            top = new CRenderedObjectOctreeNode(2000, -2000, 2000, -2000, 2000, -2000, 100);
        }

        public void setRenderParameters(BoundingFrustum frustum, Matrix view, Matrix projection)
        {
            //m_cameraFrustum = frustum;
            top.setRenderParameters(frustum, view, projection);
        }


        //bool AddNode(Vector3 vector, T obj);
        public Boolean AddNode(CRenderedObject obj)
        {
            CRenderedObjectOctreeLeaf m_leaf = new CRenderedObjectOctreeLeaf(obj);

            return top.AddNode(m_leaf);
        }

        /// <summary> Remove a object out of the organizer at a location.</summary>
        /// <param name="x">up-down location (x, y)</param>
        /// <param name="y">left-right location (y, x)</param>
        /// <returns> the object removed, null if the object not found.</returns>
        public CRenderedObject RemoveNode(CRenderedObject obj)
        {
            return top.RemoveNode(obj);
        }

        /// <summary>Clear the octree.</summary>
        public void Clear()
        {
            //base.Clear<CRenderedObject>();
            top.Clear();
        }

        public void setRange(Vector3 vector, float radius)
        {
            top.setRange(vector, radius);
        }


        public void Render()
        {
            top.Render();
        }

        public void Render(BoundingFrustum frustum, Vector3 vector, Double radius, Matrix cameraView, Matrix cameraProjection)
        {
            top.Render(frustum, vector, radius, cameraView, cameraProjection);
        }

        public GameState Update(TimeSpan gameTime, TimeSpan elapsedTime)
        {

            return top.Update(gameTime, elapsedTime);
        }
        

    }
}